package model.boardlist;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class BoardListService {
	private BoardListDao boardListDao;

	public void setBoardListDao(BoardListDao boardListDao) {
		this.boardListDao = boardListDao;
	}

	/**
	 * 게시판 명을 받아오는 메서드 (메뉴관리에 사용)
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public List<BoardListVO> boardList() throws SQLException {
		List<BoardListVO> list = boardListDao.boardList();
		//System.out.println(list);
		return list;
	}

	/**
	 * 게시물 추가
	 * 
	 * @param blvo
	 * @throws SQLException
	 */
	public void addBoard(BoardListVO blvo) throws SQLException {
		System.out.println(blvo);
		Object boardOrder = boardListDao.maxBoardOrder(blvo.getId());
		if (boardOrder == null) {
			blvo.setBoard_order(1);
		}else{
			//Object 넘어온 board_order 를 int 형태로 캐스팅
			int order=(int) boardOrder;
			blvo.setBoard_order(order+1);
		}		
		System.out.println(boardOrder);
		boardListDao.addBoard(blvo);

	}

	public void delBoard(int bno) throws SQLException {
		boardListDao.delBoardList(bno);

	}

	public void boardNameModify(BoardListVO blvo) throws SQLException {
		boardListDao.boardNameModify(blvo);
	}

	public void boardOrderModify(ArrayList list) throws SQLException {
		for (int i = 0; i < list.size(); i++) {
			HashMap map = (HashMap) list.get(i);
			boardListDao.boardOrderModify(map);
		}
	}
}
